{include file="public/header" /}
<body class="gray-bg">
<div class="layui-fluid layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body layui-form">
            <div class="layui-row layui-col-space10 layui-form-item ">
                <input type="hidden" name="id" value="{$page.id}">
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="title" value="{$page.title}" lay-verify="required" placeholder="文章标题">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">关键字</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input " name="keyword" value="{$page.keyword}" lay-verify="required" placeholder="文章关键字">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea name="remark" class="layui-textarea" lay-verify="required" placeholder="文章描述">{$page.remark}</textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">图片上传</label>
                    <input type="hidden" name="photo" id="lay-img" value="{$page.photo}">
                    <div class="layui-input-block">
                        <div id="lay-upload">上传图片</div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                            预览图：
                            <div class="layui-upload-list" id="lay-img-list">
                                <img class="layui-append-img" src="{$page.photo}" onerror="this.src='/static/admin/images/no_img.jpg'">
                            </div>
                        </blockquote>
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                    <label class="layui-form-label">文章内容</label>
                    <div class="layui-input-block" >
                        <textarea class="layui-textarea" name="content" lay-verify="content" id="LAY_editor" placeholder="文章内容">{$page.content}</textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">链接</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input " name="url" value="{$page.url}"  placeholder="链接">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="开启" {if condition="$page['status'] == 1"}  checked {/if}>
                        <input type="radio" name="status" value="2" title="关闭" {if condition="$page['status'] == 2"}  checked {/if}>
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                        </button>
                        <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>

    // 图片上传
    if("{$configState}" == 0){
        wk.uploadImg({size:2,type:'jpg,jpeg,png',url:"{:url('Upload/upload')}",domain:"{:config('DOMAIN')}"});
    }else {
        wk.uploadImg({size:2,type:'jpg,jpeg,png',url:"{:url('admin/upload/uploadLocality')}"});
    }

    // layedit富文本编辑器
    var index = wk.layeditor('LAY_editor');

    layui.use(['form','upload','layedit','element'], function() {
        var form = layui.form
            , layedit = layui.layedit
            , upload = layui.upload
            , element = layui.element

        //layedit富文本
        layedit.set({
            uploadImage: {
                url: '/admin/Upload/layUpload',
                type: 'post'
            }
        });

        var index = layedit.build('LAY_editor', {height: 400});

        form.verify({
            content:function(value,item){
                if(layedit.getContent(index) == ''){
                    return '请填写文章内容';
                }
            }
        });

        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            data.field.content = layedit.getContent(index);
            $.ajax({
                url:"{:url('edit_page')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            setTimeout(function () {
                                wk.layer_close();
                                window.location.href="{:url('Article/index_page')}";
                            },100);
                        })
                    } else {
                        $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
                        wk.error(res.msg);
                        return false;
                    }
                }
            })
        });
    });
</script>
</body>
</html>